import FileSaver from 'file-saver';
import XLSX from 'xlsx';

export const downExcle = (sheetNames, formName, formHeader, formData) => {
	let workbook = XLSX.utils.book_new();
	/* convert table 'table1' to worksheet named "Sheet1" */
	// let ws1 = XLSX.utils.table_to_sheet(document.getElementById('Table1'));
	workbook.SheetNames = sheetNames;
	sheetNames.map((item, index) => {
		let ws = XLSX.utils.aoa_to_sheet([formHeader]);
		XLSX.utils.book_append_sheet(workbook, ws, `${item}${index}`);
	});
	// 	/* convert table 'table2' to worksheet named "Sheet2" */
	// 	let ws2 = XLSX.utils.table_to_sheet(document.getElementById('Table2'));
	// 	XLSX.utils.book_append_sheet(workbook, ws2, 'sheet2');

	// 	/* get binary string as output */
	let wbOut = XLSX.write(workbook, {
		bookType: 'xlsx',
		bookSST: true,
		type: 'array'
	});
	try {
		FileSaver.saveAs(new Blob([wbOut], { type: 'application/octet-stream' }), `${formName}.xlsx`);
	} catch (e) {
		if (typeof console !== 'undefined') {
			console.log(e, wbOut);
		}
	}
	// 	return wbout;
};
const getCellData = formHeader => {
	formHeader.map(cell => {
		return {};
	});
};
